<?php
/**
 * @Author:      lyt
 * @DateTime:  2017-07-27 10:11:38
 * @Description: 套餐卡门店信息
 */
class ServiceCardBaseShopUse extends Eloquent
{
    protected $table = "service_card_base_shop_use";
    
    /**
     * @Author:         zk
     * @DateTime:       18-5-28 下午1:50
     * @Description:    根据套餐卡模板id数组获取相应套餐卡的适用门店信息
     * @param array $base_id_arr 套餐卡模板id的数组
     * @return array [以套餐卡模板id为key、以门店所属城市id为key的多维数组]
     */
    public static function getShopUseInfo($base_id_arr){
        if(!is_array($base_id_arr)){
            return [];
        }
        //查询信息
        $shop_use_select_arr = [
            'service_card_base_shop_use.service_card_base_id', 'service_card_base_shop_use.shop_id', 
            'maintenance_shops.name', 'maintenance_shops.city_id', 'maintenance_shops.tel_phone', 
            'resource_city.city_name'
        ];
        $shop_use = ServiceCardBaseShopUse::leftJoin('maintenance_shops', 'service_card_base_shop_use.shop_id', '=', 'maintenance_shops.id')
                ->leftJoin('resource_city', 'maintenance_shops.city_id', '=', 'resource_city.id')
                ->where('service_card_base_shop_use.status', 1)
                ->whereIn('service_card_base_shop_use.service_card_base_id', $base_id_arr)
                ->where('maintenance_shops.status', 1)
                ->select($shop_use_select_arr)
                ->get();
        $shop_info_arr = [];    //适用门店信息数组
        foreach ($shop_use as $v) {
            if($v){
                $temp_arr = [
                    'shop_id' => $v->shop_id,
                    'city_name' => $v->city_name,
                    'name' => $v->name,
                    'tel_phone' => $v->tel_phone,
                ];
                $shop_info_arr[$v->service_card_base_id][$v->city_id][] = $temp_arr;
            }
        }
        
        return $shop_info_arr;
    }
    
}